<template>
	<view>
		<view class="query-area">
			<!-- <QSInput :name="formName" variableName="carNum" title="车牌号" required v-model="values.carNum" :itemDisabled="itemDisabled"></QSInput> -->
			
			<QSKeyboardPlate :name="formName"
			ref="carNumRef"
			variableName="carNum" 
			title="车牌号"
			height= "0.65"
			required
			:value="values.carNum"
			placherhold="请输入车牌号" />
			<button class="query-btn" type="primary" @tap="getData">查询</button>
		</view>
		
		<scroll-view class="purchase-body" scroll-y="true" @scrolltolower="scrolltolower" @scrolltoupper="scrolltoupper" @scroll="scroll" @touchstart="touchstart" @touchend="touchend">
			<my-unit v-for="(item,index) in listData" :key="index" :unitName="unitName" :infoArray="[item]" :idx="index"></my-unit>
		</scroll-view>
	</view>
</template>

<script>
	import QSApp from '@/components/QS-inputs-split/js/app.js';
	import myUnit from '@/components/myUnits/purchaseUnit/unit.vue'
	import myPull from '@/static/js/myPull.js'
	import myLoading from '@/components/myLoading/myLoading.vue'
	
	
	export default {
		components: {
			myUnit,
			myLoading
		},
		data() {
			return {
				unitName: 'policeUnit',
				title: 'Hello',
				formName: 'queryInput',
				values: {
					carNum: '',
				},
				itemDisabled: false,
				nCode: '',

				pageSize:4,
				curPage:0,
				queryData:{},
				sumDataCount:0,
			}
		},
		mixins:[myPull({})],
		methods: {
			getData(){
				let _this = this;
				
				QSApp.getForm(_this.formName).then(res=>{
					console.log('获取表单数据成功:' + JSON.stringify(res));
					if(res.data.carNum == null || res.data.carNum == ''){
						uni.showToast({
							title: "请输入车牌号",
							icon: "none"
						});
						return ;
					}
					_this.curPage = 0;
					_this.listData = [];
					_this.getList(res.data.carNum.data);
					
				}).catch(err=>{
					console.log('获取表单数据失败:' + JSON.stringify(err));
				
					uni.showToast({
						title: "请检查表单数据",
						icon: "none"
					});
				});
			},
			
			getList(carNum){
				let _this = this;
				
				let params = {};
				let url = "/rest/passQuery";
				
				params.limit = _this.pageSize;
				params.page = _this.curPage;
				params.createTimeOrder = "DESC";
				params.carNum = carNum;
				params.carNumOperator = "eq";

				
				_this.$api.request(url, params, failres => {
					uni.showToast({
						title: "服务器异常",
						icon: "none"
					});
				}).then(rsp => {
					//表单提交成功
					//提交图片
					console.log('获取表单数据成功:' + JSON.stringify(rsp));
					if(rsp.count==0){
						uni.showToast({
							title: "没有查到相关记录",
							icon: "none"
						});
					}else{
						_this.sumDataCount = rsp.count;
						//_this.listData = rsp.data;
						_this.curPage++;
						_this.listData = (_this.listData || []).concat(rsp.data);
						
					}
					//_this.tabModelData[_this.initTabIndex].badge = ''+_this.sumDataCount;
				})
			},
			/**
			 * @name 触底加载
			 */
			scrolltolower(event){
				console.log("scrolltolower...");
				//this.getList()
			},
			
			scroll(e){
				// 重新设置pulldown
				this.setPullDown(e.detail.scrollTop<10)
			},
			
			scrolltoupper(){
				
			},
		}
	}
</script>

<style>
	.query-area{
		display: flex;
		flex-direction: row;
		margin-top: 50upx;
		margin-bottom: 50upx;
		margin-right: 50upx;
	}
	
	.query-btn{
		width:200upx;
	}
</style>
